﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Controls_YearCalendar : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    protected void lv_ItemDataBound(object sender, ListViewItemEventArgs e)
    {
        if (e.Item.ItemType == ListViewItemType.DataItem)
        {
            foreach (DateTime d in SelectedDates)
            {
                (e.Item.FindControl("cl") as Calendar).SelectedDates.Add(d);
                (e.Item.FindControl("cl") as My.MyCalendar).MySelectedDates.Add(d);
            }
        }
    }

    protected void cl_SelectionChanged(object sender, EventArgs e)
    {
        CurrentAddDates.AddRange((sender as My.MyCalendar).CurrentAddDates);
        CurrentDeleteDates.AddRange((sender as My.MyCalendar).CurrentDeleteDates);

        if (SelectionChanged != null)
        {
            SelectionChanged(this, e);
        }
    }

    protected void cl_DayRender(object sender, DayRenderEventArgs e)
    {
        if (e.Day.IsOtherMonth)
        {
            //e.Cell.Text = string.Empty;
            e.Cell.Text = "&nbsp;";
            e.Cell.BackColor = System.Drawing.Color.White;
        }
    }

    public event EventHandler SelectionChanged;

    public List<DateTime> CurrentAddDates
    {
        get
        {
            if (Context.Items[this.ID + "CurrentAddDates"] == null)
            {
                Context.Items[this.ID + "CurrentAddDates"] = new List<DateTime>();
            }

            return Context.Items[this.ID + "CurrentAddDates"] as List<DateTime>;
        }
    }

    public List<DateTime> CurrentDeleteDates
    {
        get
        {
            if (Context.Items[this.ID + "CurrentDeleteDates"] == null)
            {
                Context.Items[this.ID + "CurrentDeleteDates"] = new List<DateTime>();
            }

            return Context.Items[this.ID + "CurrentDeleteDates"] as List<DateTime>;
        }
    }

    public List<DateTime> SelectedDates
    {
        get
        {
            if (Context.Items["SelectedDates"] == null)
            {
                Context.Items["SelectedDates"] = new List<DateTime>();
            }

            return Context.Items["SelectedDates"] as List<DateTime>;
        }
    }

    public int YY
    {
        get
        {
            return (int)ViewState["YY"];
        }
        set
        {
            ViewState["YY"] = value;
        }
    }

    List<int> _MonthData = null;

    public List<int> MonthData
    {
        get
        {
            if (_MonthData == null)
            {
                _MonthData = new List<int>();

                for (int i = 1; i <= 12; i++)
                {
                    _MonthData.Add(i);
                }
            }

            return _MonthData;
        }
    }
}